/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package panelAdmin;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author DuyDang
 */
public class CustomerTableModel extends AbstractTableModel {

    private ArrayList<Customer> list;
    private String[] columnnames = new String[]{"ID", "Password", "Name", "PhoneNumber", "Balance"};

    public CustomerTableModel(ArrayList<Customer> list) {
        this.list = list;
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return columnnames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnnames[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Customer customer = list.get(rowIndex);
        if (columnIndex == 0) {
            return customer.getId();
        } else if (columnIndex == 1) {
            return customer.getPassword();
        } else if (columnIndex == 2) {
            return customer.getName();
        } else if (columnIndex == 3) {
            return customer.getPhoneNumber();
        } else {
            return customer.getBalance();
        }
    }

//    @Override
//    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//        Customer customer = list.get(rowIndex);
//        if (columnIndex == 0) {
//            customer.setId(aValue.toString());
//        } else if (columnIndex == 1) {
//            customer.setPassword(aValue.toString());
//        } else if (columnIndex == 2) {
//            customer.setName(aValue.toString());
//        } else if (columnIndex == 3) {
//            customer.setPhoneNumber(aValue.toString());
//        } else {
//            customer.setBalance(Integer.parseInt(aValue.toString()));
//        }
//    }

//    @Override
//    public Class<?> getColumnClass(int columnIndex) {
//        Object o = getValueAt(0, columnIndex);
//        if (o == null) {
//            return Object.class;
//        } else {
//            return o.getClass();
//        }
//    }

//    @Override
//    public boolean isCellEditable(int rowIndex, int columnIndex) {
//        if(columnIndex == 4){
//            return true;
//        }else{
//            return false;
//        }
//    }
}
